package com.cjh.controller;

import com.cjh.entity.Order;
import com.cjh.service.HelloService;
import org.apache.rocketmq.spring.core.RocketMQTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Date;

/**
 * @author cjh
 * @date 2021/3/29 14:19
 */

@RestController
@RequestMapping("/provider")
public class ProviderController {

    @Autowired
    private HelloService helloService;

    @Value("${server.port}")
    private String port;

    @GetMapping("/index")
    public String index() {
        return port;
    }

    @GetMapping("/test1")
    public String test1(){
        this.helloService.test();
        return "test1";
    }

    @GetMapping("/test2")
    public String test2(){
        this.helloService.test();
        return "test2";
    }

    @Autowired
    private RocketMQTemplate rocketMQTemplate;

    @GetMapping("/create")
    public Order create(){
        Order order = new Order(
                1,
                "张三",
                "123123",
                "软件园",
                new Date()
        );
        this.rocketMQTemplate.convertAndSend("myTopic",order);
        return order;
    }
}
